package ShenBlueCenter.json;

import java.io.IOException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ShenBlueDao.CreditCardDao;
import ShenBlueInc.Center.Card_Center;
import net.sf.json.JSONArray;

/**
 * Servlet implementation class CeaditCard_Service_Json
 */
@WebServlet("/imp/CeaditCard_Service_Json")
public class CeaditCard_Service_Json extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CeaditCard_Service_Json() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json");
		response.setCharacterEncoding("utf8");
		int page=Integer.parseInt(request.getParameter("page")==null?"0":request.getParameter("page"));
		int limit=Integer.parseInt(request.getParameter("limit")==null?"10":request.getParameter("limit"));
		String card_id=request.getParameter("card_id")==null?"":request.getParameter("card_id");
		String time_start=request.getParameter("time_start")==null?"":request.getParameter("time_start");
		String time_end=request.getParameter("time_end")==null?"":request.getParameter("time_end");
		String bank_id=request.getParameter("bank_id")==null?"":request.getParameter("bank_id");
		HttpSession session=request.getSession();
		String user_id=(String) session.getAttribute("User_id");
		Card_Center CarcC=new Card_Center();
		System.out.println(page+" "+limit+" "+card_id+" "+time_start+" "+time_end+" "+bank_id+" "+user_id);
		LinkedList<CreditCardDao> list=CarcC.ServiceCard(((page<1?0:page-1)*(limit<1?10:limit))+"", (limit<1?10:limit)+"", user_id, card_id, time_start, time_end, bank_id);
		String jsons="{\"code\":0,\"msg\":\"\",\"count\":"+CarcC.ServiceCardCount(user_id, card_id, time_start, time_end, bank_id)+",\"data\":"+JSONArray.fromObject(list)+"}";
		response.getWriter().write(jsons);
	}

}
